import { baseRequestClient, requestClient } from '#/api/request';

export namespace Area {
  export interface Params {
    attr1: null;
  }

  export interface Row {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date | null;
    remark: string;
    params: Params;
    areaId: number;
    areaCode: string;
    areaName: string;
    locationId: number;
    area: number;
    maxLoa: number;
    positionX: number;
    positionY: number;
    positionZ: number;
    enableFlag: string;
    frozenFlag: string;
    productMixing: string;
    batchMixing: string;
    attr2: null;
    attr3: number;
    attr4: number;
    attr1: boolean | null | string;
  }

  export interface GetListParams {
    pageNum: number;
    pageSize: number;
    locationId: string;
  }
  export interface GetListReturn {
    total: number;
    rows: Row[];
    code: number;
    msg: string;
  }
}

// 获取列表
export const getAreaTableList = (params: Area.GetListParams) =>
  requestClient.get<Area.GetListReturn>('/mes/wm/area/list', {
    params,
  });

// 修改库区设置
export const updateArea = (data: Area.Row) =>
  requestClient.put<Area.GetListReturn>('/mes/wm/area', data);
export const updateAreaStatus = (data: {
  frozenFlag: string;
  locationId: string;
}) => requestClient.put<Area.GetListReturn>('/mes/wm/area', data);

// 增加库区设置
export const addArea = (data: Area.Row) =>
  requestClient.post<Area.GetListReturn>('/mes/wm/area', data);

// 删除库区设置
export const deleteArea = (id: string) =>
  requestClient.delete<Area.GetListReturn>(`/mes/wm/area/${id}`);

// 获取自动生成编码
export const getAreaCode = () =>
  baseRequestClient.get<any>('/system/autocode/get/AREA_CODE');
